package com.battcn.platform.service.sys.impl;

import com.battcn.framework.mybatis.page.DataGrid;

import com.battcn.platform.mapper.sys.OperateMapper;
import com.battcn.platform.pojo.dto.sys.OperateDto;
import com.battcn.platform.pojo.dto.sys.ShiroPermission;
import com.battcn.platform.pojo.po.sys.Operate;
import com.battcn.platform.service.sys.OperateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Levin
 */
@Service
public class OperateServiceImpl extends BaseServiceImpl<Operate> implements OperateService {

    private final OperateMapper operateMapper;

    @Autowired
    public OperateServiceImpl(OperateMapper operateMapper) {
        this.operateMapper = operateMapper;
    }

    @Override
    public List<Operate> listOperateByRoleIdAndMenuId(String roleId, Integer menuId) {
        return this.operateMapper.listOperateByRoleIdAndMenuId(roleId, menuId);

    }

    @Override
    public PageInfo<OperateDto> listOperateByPage(DataGrid grid) {
        grid.getOrderBy();
        return PageHelper.startPage(grid.getPageNum(), grid.getPageSize())
                .doSelectPageInfo(this.operateMapper::listOperateByPage);
    }

    @Override
    public List<ShiroPermission> listShiroPermissions(String roleId) {
        return this.operateMapper.listShiroPermissionByRoleId(roleId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteById(Object key) {
        return operateMapper.deleteById((String)key) > 0;
    }

}
